package main

import (
	"context"
	"fmt"

	"gitee.com/xiarrunliang/go-learning/learn_begin/concurrency_learn/ContextLearn/p1"
	"gitee.com/xiarrunliang/go-learning/learn_begin/concurrency_learn/ContextLearn/p2"
)

func main() {
	fmt.Println("run in output")

	ctx := context.WithValue(context.Background(), p1.Mykey1, "123")
	ctx = context.WithValue(ctx, p2.Mykey1, true)

	fmt.Println(ctx.Value(p1.Mykey1)) //123
	fmt.Println(ctx.Value(p2.Mykey1)) //true

	// 这个会被覆盖
	ctx = context.WithValue(ctx, p1.MyKeyTest1, "ceshi11")
	ctx = context.WithValue(ctx, p2.MyKeyTest1, true)
	fmt.Println(ctx.Value(p1.MyKeyTest1)) //true
	fmt.Println(ctx.Value(p2.MyKeyTest1)) //true

	ctx = context.WithValue(ctx, p1.MyKeyTest2, "ceshi22")
	ctx = context.WithValue(ctx, p2.MyKeyTest2, true)
	fmt.Println(ctx.Value(p1.MyKeyTest2)) //ceshi22
	fmt.Println(ctx.Value(p2.MyKeyTest2)) //true

	context.WithCancel(ctx)
}
